<?php
session_start();

if (!isset($_SESSION['AdminId']) || $_SESSION['AdminId'] == "") {
    echo "<script type='text/javascript'>location.href='admin.php'</script>";
}

require_once 'common/config.php';
require_once 'common/conn.php';
require_once 'common/function.php';

require_once 'db/itemType.db.php';

$id = isset($_GET['id']) ? $_GET['id'] : "";

if ($id == "") {
    $itemTypeName = "";
} else {
    $dbc = new DBC();

    $itemTypeDb = new ItemTypeDb($dbc);

    $data = $itemTypeDb->getItemTypeById($id);

//$itemTypeName = mb_convert_encoding($data[0]['item_type'], "UTF-8", "GBK");

    $itemTypeName = $data[0]['item_type'];

    $dbc->close();
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title>商品类型修改</title>
        <meta charset="UTF-8">
        <link href="<?php echo $flatUi; ?>dist/css/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">        
    </head>
    <body>

        <div class="container">  
            <div style="text-align: center">
                <h1>   
                    <?php
                    if ($id == "") {
                        echo "商品类型增加";
                    } else {
                        echo "商品类型编辑";
                    }
                    ?>
                </h1>
            </div>
            <form class="form-horizontal" role="form" action="action/itemType.action.php" method="POST">                
                <div class="form-group">
                    <label class="col-sm-2 control-label">名称</label>
                    <div class="col-sm-10">
                        <input class="form-control" id="itemTypeName" name="itemTypeName" type="text" value="<?php echo $itemTypeName; ?>" required>
                    </div>
                </div>
                <div style="width:100%; text-align: center">         
                    <?php if ($id == "") { ?>
                        <input type="hidden" name="action" value="create" />
                    <?php } else { ?>
                        <input type="hidden" name="idx" value="<?php echo $data[0]['id_x']; ?>"/>
                        <input type="hidden" name="action" value="edit" />
                    <?php } ?>
                    <input type="submit" class="btn btn-primary" value="保存"/>
                </div>
            </form>
        </div> 
    </body>
</html>